﻿import QtQuick 2.0

Item {
    id: root
    width: 400
    height: 300

    property var mapSiteSize: Qt.size(32, 32)   // 每个房间占3*3 格子

    property real _North: 0
    property real _South: 1
    property real _East: 2
    property real _West: 3

    Connections{
        target: widget
        onNotifyMapSite: {
            createMapSite(roomNo, type, direction)
        }
    }

    function createMapSite(roomNo, type, direction)
    {
        console.log(roomNo, type, direction)
        var obj = Qt.createComponent("MapSite.qml").createObject(root)
        obj.source = "qrc:/images/image/" + type + ".png"

        if(direction === _North)
        {
            obj.x = mapSiteSize.width + (roomNo * mapSiteSize.width * 3)
            obj.y = 0
        }
        else if(direction === _South)
        {
            obj.x = mapSiteSize.width + (roomNo * mapSiteSize.width * 3)
            obj.y = mapSiteSize.height * 2
        }
        else if(direction === _East)
        {
            obj.x = mapSiteSize.width * 2 + (roomNo * mapSiteSize.width * 3)
            obj.y = mapSiteSize.height * 1
        }
        else if(direction === _West)
        {
            obj.x = 0 + (roomNo * mapSiteSize.width * 3)
            obj.y = mapSiteSize.height * 1
        }
        else{
            // room
            obj.x = mapSiteSize.width + (roomNo * mapSiteSize.width * 3)
            obj.y = mapSiteSize.height * 1
        }
    }

}
